package com.atqinke.algorithm;

/**
 * @BelongsProject: BasicConnection
 * @BelongsPackage: com.atqinke.algorithm
 * @Author: NieHk
 * @CreateTime: 2022-08-16  18:15
 * @Description: 插入排序
 * @Version: 1.0
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] array = new int[]{11, 45, 77, 62, 55, 41, 37, 29, 11, 72, 13, 489, 132, 89, 78, 791, 13, 45, 96};
        insertSort(array);
        for (int i : array) {
            System.out.print(i + ",");
        }
    }


    public static void insertSort(int[] array) {
        int length = array.length;

        for (int i = 1; i < length; i++) {
            for (int j = i; j > 0; j--) {
                if (array[j - 1] > array[j]) {
                    int temp = array[j];
                    array[j] = array[j - 1];
                    array[j - 1] = temp;
                } else {
                    break;
                }
            }
        }


    }
}
